package com.ckv.qcm.model;

import java.util.ArrayList;

import com.ckv.qcm.model.dao.QuestionDAO;

public class Question {

	private long id;
	private String description;
	private String statement;
	private String image;
	private AnswerType answerType;
	private boolean isMarked = false;

	private ArrayList<Answer> answers;
	private ArrayList<Theme> themes;

	private static QuestionDAO dao = new QuestionDAO();





	public Question()
	{

		super();
	}

	public Question(long id, String description, String statement,
			String image, AnswerType answerType) {
		super();
		this.id = id;
		this.description = description;
		this.statement = statement;
		this.image = image;
		this.answerType = answerType;
	}

	public Question(long id, String description, String statement,
			String image, AnswerType answerType, ArrayList<Answer> answers,
			ArrayList<Theme> themes) {
		super();
		this.id = id;
		this.description = description;
		this.statement = statement;
		this.image = image;
		this.answerType = answerType;
		this.answers = answers;
		this.themes = themes;
	}

	public Question create() {
		return dao.create(this);
	}

	public static Question find(long id) {
		return dao.find(id);
	}

	public static ArrayList<Question> findAll() {
		return dao.findAll();
	}

	public boolean delete() {
		return dao.delete(this);
	}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getStatement() {
		return statement;
	}

	public void setStatement(String statement) {
		this.statement = statement;
	}

	public String getImage() {
		return image;
	}

	public void setImage(String image) {
		this.image = image;
	}

	public AnswerType getAnswerType() {
		return answerType;
	}

	public void setAnswerType(AnswerType answerType) {
		this.answerType = answerType;
	}

	public ArrayList<Answer> getAnswers() {
		return answers;
	}

	public ArrayList<Answer> getAnswers(boolean isValid) {
		ArrayList<Answer> answers = new ArrayList<Answer>();

		for (Answer answer : this.answers)
		{
			if (answer.isValid() == isValid) {
				answers.add(answer);
			}

		}
		return answers;
	}

	public void setAnswers(ArrayList<Answer> answers) {
		this.answers = answers;
	}

	public ArrayList<Theme> getThemes() {
		return themes;
	}

	public void setThemes(ArrayList<Theme> themes) {
		this.themes = themes;
	}

	public boolean isMarked()
	{
		return isMarked;
	}

	public void setMarked(boolean isMarked)
	{
		this.isMarked = isMarked;
	}

	@Override
	public String toString() {
		return "Question [id=" + id + ", description=" + description
				+ ", statement=" + statement + ", image=" + image
				+ ", answerType=" + answerType + ", answers=" + answers
				+ ", themes=" + themes + "]";
	}

}
